<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	template="/resources/layout/templateInterno.xhtml"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:t="http://myfaces.apache.org/tomahawk"
    xmlns:rich="http://richfaces.org/rich">
	<ui:define name="body">
	
	
	
<script>



</script>
	<div class="form">	
		<h:form  id="membroPesquisa" styleClass="form">
		<a4j:outputPanel ajaxRendered="true" id="pgMensagens" >
			  <div >
					<h:messages style="padding:5px" errorClass="errorMessage" infoClass="infoMessage"  />
			</div>
		</a4j:outputPanel>
		
		 <t:fieldset id="idfsDadosParametros" style="width:850px" legend="Filtros">
			<a4j:region>
			<div class="grid-3-12">
			<h:outputLabel  id="lbTipoPesquisa" class="form-lbl"  value="Tipo Pesquisa:"/>
				<h:selectOneRadio id="rdTipPesquisa" styleClass="form-txt"  value="#{membroRelatorioBean.tipoPesquisa}">
					<f:selectItem itemLabel="Básica" itemValue="B"/>
					<f:selectItem itemLabel="Avançada" itemValue="A"/>
					<a4j:support ajaxSingle="true" event="onclick" action="#{membroRelatorioBean.limpar}" reRender="membroPesquisa"> </a4j:support>
				</h:selectOneRadio>
			</div>
			
			<div class="field-clear"></div>
			 
				<div class="grid-3-12">
					<h:panelGroup id="pgOpcoesPesquisa">
						<h:outputLabel  id="lbOpcoes" class="form-lbl"  value="Opcão:"/>
							<h:selectOneMenu label="Opções" id="cbOpcao" styleClass="form-txt" value="#{membroRelatorioBean.parametroPesquisa.opcao}">
						 		<f:selectItem itemLabel="Selecione ..." itemValue=""/>
						 		<f:selectItems value="#{membroRelatorioBean.listaOpcoes}"  />
						 		<a4j:support ajaxSingle="true" action="#{membroRelatorioBean.limparParametro}" event="onchange" reRender="pgDataPesquisa,pgDadosPesquisa,pgMatriculaPesquisa,cbOperacao,pgSexo"> </a4j:support>
					 		</h:selectOneMenu>
					 	</h:panelGroup>
					</div>
					
					<div class="grid-2-12">
						<h:panelGroup id="pgOpcoes" >
							<h:panelGroup>
							<h:outputLabel  id="lbOperacao" class="form-lbl"  value="Operação:"/>
							<h:selectOneMenu   label="Operação" id="cbOperacao" styleClass="form-txt" value="#{membroRelatorioBean.parametroPesquisa.operacao}">
						 		<f:selectItems value="#{membroRelatorioBean.listaOperacoes}" />
					 		</h:selectOneMenu>
					 		</h:panelGroup>
					 	</h:panelGroup>
					</div>
			
				<h:panelGroup id="pgDataPesquisa" >
					<h:panelGroup  rendered="#{membroRelatorioBean.parametroPesquisa.opcao != 'coSeqMembro' and membroRelatorioBean.parametroPesquisa.opcao != 'nome' 
															and membroRelatorioBean.parametroPesquisa.opcao != 'sexo'
															and membroRelatorioBean.parametroPesquisa.opcao != null and membroRelatorioBean.parametroPesquisa.opcao != ''}">
						<div class="grid-3-12">
						<ui:define name="campoData">
							<h:outputLabel id="lbDataPesquisa" class="form-lbl" value="Data:" />
							 <rich:calendar id="clDataPesquisa"
							 				firstWeekDay="0" 
							 				showWeeksBar="false"
							 				minDaysInFirstWeek="2" 
							 				value="#{membroRelatorioBean.parametroPesquisa.dtPesquisa}"
											datePattern="dd/MM/yyyy" inputSize="10" inputClass="maskDate" enableManualInput="true" disabled="false">
							</rich:calendar> 
							</ui:define>
							<rich:jQuery id="mskDataPesquisa" selector=".maskDate" timing="onload" query="mask('99/99/9999',{placeholder:' '})" />
						</div>
					</h:panelGroup>
				</h:panelGroup>
				<h:panelGroup id="pgDadosPesquisa" >
					<h:panelGroup  rendered="#{membroRelatorioBean.parametroPesquisa.opcao == 'coSeqMembro'}">
						<div class="grid-2-12">
							<h:outputLabel class="form-lbl"  value="Matrícula:"/>				
							<h:inputText styleClass="form-txt" maxlength="9" value="#{membroRelatorioBean.parametroPesquisa.dado}" id="matriculaPesquisa" >
							 	<rich:jQuery selector="#matriculaPesquisa" query="numeric()" timing="onload"/>
							 	
							</h:inputText>
						 </div>	
					 </h:panelGroup>
				 </h:panelGroup>
				 <h:panelGroup id="pgMatriculaPesquisa" >
					 <h:panelGroup  rendered="#{membroRelatorioBean.parametroPesquisa.opcao == 'nome'}">
						  <div class="grid-5-12">
							<h:outputLabel class="form-lbl"  value="Nome:"/>				
							<h:inputText styleClass="form-txt"   value="#{membroRelatorioBean.parametroPesquisa.dado}" id="nomePesquisa" />
						 </div>
					 </h:panelGroup>
				 </h:panelGroup>
				  <h:panelGroup id="pgSexo" >
					 <h:panelGroup  rendered="#{membroRelatorioBean.parametroPesquisa.opcao == 'sexo'}">
					 	<div class="grid-2-12">
							<h:outputLabel  id="lbSexo" class="form-lbl"  value="Sexo:"/>
							<h:selectOneMenu  required="true" label="Sexo" id="cbSexo" styleClass="form-txt" value="#{membroRelatorioBean.parametroPesquisa.dado}">
						 		<f:selectItem itemLabel="Masculino" itemValue="M"/>
						 		<f:selectItem itemLabel="Feminino" itemValue="F"/>
					 		</h:selectOneMenu>
						</div>
					</h:panelGroup>
				</h:panelGroup>
			</a4j:region>	
			<div style="padding-bottom: 20px; padding-top: 20px">
			 <h:panelGroup  id="pgTipoPesquisa">
			  
				 <a4j:outputPanel ajaxRendered="true"   rendered="#{membroRelatorioBean.tipoPesquisa == 'A'}">
					 <div class="grid-2-12">
						<a4j:commandButton id="cdbAdicionar" style="width:70px" styleClass="form-button" action="#{membroRelatorioBean.adicionar}" process="pgDadosPesquisa" reRender="pgMensagens,membroParmetroTable,idfsDadosParametros" value="Adicionar" >
						</a4j:commandButton>
					</div>
				 </a4j:outputPanel>
			</h:panelGroup>
			</div>
			<div class="field-clear"></div>
			<div class="grid-2-12">
					<h:outputLabel  id="lbTipoMembro" class="form-lbl"  value="Tipo:"/>
					<h:selectOneMenu id="cbTipoMembro" styleClass="form-txt" value="#{membroRelatorioBean.tipoMembro}">
				 		<f:selectItem itemLabel="Todos" itemValue="T"/>
				 		<f:selectItem itemLabel="Membro" itemValue="M"/>
				 		<f:selectItem itemLabel="Visitante" itemValue="V"/>
				 		<a4j:support ajaxSingle="true" event="onchange" action="#{membroRelatorioBean.pesqOpcoesTipoMembro}" reRender="idfsDadosParametros,cbOpcao,membroPesquisa,idExibirPesquisarTabela"> </a4j:support>
			 		</h:selectOneMenu>
				</div>	
			<h:panelGroup id="pgIgrejaPertence" >
				<div class="grid-3-12">
					<h:outputLabel  id="lbLocalPertencePesquisa"  class="form-lbl"  value="Igreja:"/>
					<h:selectOneMenu  styleClass="form-txt" converter="indexConverter" id="cbLocalFrequenciaPesquisa"  value="#{membroRelatorioBean.igreja}">
					 		<f:selectItem itemLabel="Todos" itemValue=""/>
						   <t:selectItems value="#{membroRelatorioBean.listaIgreja}" var="igreja" itemLabel="#{igreja.nome}" itemValue="#{igreja}"/>
					</h:selectOneMenu>
				</div>
			</h:panelGroup>
				<div class="grid-2-12">
					<h:outputLabel  id="lbStatus" class="form-lbl"  value="Status:"/>
					<h:selectOneMenu id="cbStatusPesquisa" styleClass="form-txt" value="#{membroRelatorioBean.status}">
				 		<f:selectItem itemLabel="Todos" itemValue=""/>
				 		<f:selectItem itemLabel="Ativo" itemValue="A"/>
				 		<f:selectItem itemLabel="Inativo" itemValue="I"/>
			 		</h:selectOneMenu>
				</div>	
			
		</t:fieldset>
		
			<div class="field-clear"></div>
			 <h:panelGroup  id="idExibirPesquisarTabela">
			  <h:panelGroup  rendered="#{membroRelatorioBean.tipoPesquisa == 'A'}">
				<div style="padding-bottom: 20px" >
				 	<rich:dataTable  rowClasses="odd, even" rows="10"
		                    			styleClass="dataTable rich-table rich-table-cell ui-widget-content ui-grid-content"
	                    			
	                    			width="750" border="0" id="membroParmetroTable"  var="parametro" value="#{membroRelatorioBean.listaParametros}" >
					  <f:facet  name="header">
	                    <rich:columnGroup >
	                            <rich:column style="text-align: center"  styleClass="ui-state-default" >
	                                <strong><h:outputText value="Opcões" /></strong>
	                            </rich:column>
	                            <rich:column style="text-align: center"  styleClass="ui-state-default" >
	                                <strong><h:outputText value="Operação" /></strong>
	                            </rich:column>
	                            <rich:column style="text-align: center"  styleClass="ui-state-default" >
	                                <strong><h:outputText value="Dado" /></strong>
	                            </rich:column>
	                            
	                             <rich:column style="text-align: center"  styleClass="ui-state-default" >
	                                <strong><h:outputText value="Excluir" /></strong>
	                            </rich:column>
	                    	</rich:columnGroup>
	                  </f:facet>
	 				<rich:columnGroup >	
	 					<rich:column style="text-align:center" >
	 					<h:outputText value="#{parametro.dsOpcao}" />
						</rich:column>	
						<rich:column style="text-align:center">
							<h:outputText value="#{parametro.dsOperacao}" />
						</rich:column>	
						 <rich:column rendered="#{parametro.dado != null}" style="text-align:center">
							<h:outputText value="#{parametro.dado}" />
						</rich:column>
						 <rich:column rendered="#{parametro.dtPesquisa != null}" style="text-align:center">
							<h:outputText value="#{parametro.dtPesquisa}" />
						</rich:column>
						
						
						<rich:column style="text-align: center;" >
							<a4j:commandLink id="removerFuncao" ajaxSingle="true" action="#{membroRelatorioBean.excluir}" reRender="pgMensagens,membroParmetroTable"  >
								 <h:graphicImage value="/resources/imagens/ico_excluir.gif" id="gIExcluir" styleClass="hidelink"/>
								 <f:setPropertyActionListener target="#{membroRelatorioBean.parametroSelecionado}" value="#{parametro}"/>  
							</a4j:commandLink>						
						</rich:column>
					</rich:columnGroup>
				</rich:dataTable>
			</div>
		</h:panelGroup>
		</h:panelGroup>
		 <div class="field-clear"></div>
		  <h:panelGroup  id="idExibirPesquisar">
			  <h:panelGroup  rendered="#{membroRelatorioBean.tipoPesquisa == 'A'}">
				 <div class="grid-2-12">
						<a4j:commandButton id="cdbPesquisar" ajaxSingle="true" process="cbLocalFrequenciaPesquisa,cbStatusPesquisa,cbTipoMembro" styleClass="form-button" action="#{membroRelatorioBean.pesquisar}" 
						reRender="pgMensagens,membroParmetroTable,membroPesquisaTable,pgResultadoPesquisa,pgResultados" value="Pesquisar" >
						</a4j:commandButton>
				</div>
			</h:panelGroup>
			 <a4j:outputPanel ajaxRendered="true"   rendered="#{membroRelatorioBean.tipoPesquisa == 'B'}">
					 <div class="grid-2-12">
						<a4j:commandButton id="cdbPesquisarSimples" ajaxSingle="true"  
											process="nomePesquisa,matriculaPesquisa,clDataPesquisa,cbTipoMembro,cbSexo,
											cbLocalFrequenciaPesquisa,cbStatusPesquisa,cbOpcao,cbOperacao" 
											styleClass="form-button" action="#{membroRelatorioBean.pesquisarSimples}" 
							reRender="membroPesquisa" value="Pesquisar" >
						</a4j:commandButton>
					</div>
				</a4j:outputPanel>
		</h:panelGroup>
		 <div class="grid-2-12">
			<a4j:commandButton id="cdbLimpar" ajaxSingle="true" immediate="true" styleClass="form-button" action="#{membroRelatorioBean.limpar}" reRender="membroPesquisa" value="Limpar" >
			</a4j:commandButton>
		</div>
			<div class="field-clear"></div>
			<h:panelGroup id="pgResultadoPesquisa">
				<h:panelGroup >
					<div style="padding: 10px" >
					 	<rich:dataTable rowClasses="odd, even" rows="10" 
					 	rendered="#{not empty membroRelatorioBean.listaMembrosVos}"
			                    		styleClass="dataTable rich-table rich-table-cell ui-widget-content ui-grid-content"
		                    			width="750" border="0" id="membroPesquisaTable"  var="membroVo" value="#{membroRelatorioBean.listaMembrosVos}" >
						  	<f:facet  name="header">
		                    <rich:columnGroup >
		                            <rich:column style="text-align: center; width:20px"  styleClass="ui-state-default" >
		                                <strong><h:outputText value="Matrícula" /></strong>
		                            </rich:column>
		                            <rich:column style="text-align: center;width:330px"  styleClass="ui-state-default" >
		                                <strong><h:outputText value="Nome" /></strong>
		                            </rich:column>
		                            <rich:column style="text-align: center;width:150px"  styleClass="ui-state-default" >
		                                <strong><h:outputText value="Igreja" /></strong>
		                            </rich:column>
		                            <rich:column style="text-align: center;width:30px"  styleClass="ui-state-default" >
		                                <strong><h:outputText value="Status" /></strong>
		                            </rich:column>
		                             <rich:column style="text-align: center;width:30px"  styleClass="ui-state-default" >
	                                <strong><h:outputText value="Ação" /></strong>
	                            </rich:column>
		                  </rich:columnGroup>
		                  </f:facet>
		 					<rich:columnGroup >	
		 					<rich:column style="text-align:center" >								
								<h:outputText rendered="#{membroVo.coSeqMembro != null}" value="#{membroVo.coSeqMembro}" />
								<h:outputText rendered="#{membroVo.coSeqMembro == null}" value="-" />
							</rich:column>		
							 <rich:column style="text-align:left">
								<h:outputText value="#{membroVo.nome}" />
							</rich:column>
							<rich:column style="text-align:left">
								<h:outputText value="#{membroVo.noIgrejaPertence}" />								
							</rich:column>
							<rich:column style="text-align:left">
							<h:outputText rendered="#{membroVo.inativo}" value="INATIVO" />
							<h:outputText rendered="#{!membroVo.inativo}" value="ATIVO" />
							</rich:column>
							<rich:column style="text-align:center">
							<a4j:commandLink id="addMembro" ajaxSingle="true" 
								action="#{membroRelatorioBean.adicionarMembro}"
									 reRender="pgExibirMembroSelecionados"  >
								 <h:graphicImage value="/resources/imagens/btn_adicionar.png" id="gIAddMembroVos" styleClass="hidelink"/>
							   <f:setPropertyActionListener target="#{membroRelatorioBean.membroVoSelecionado}" value="#{membroVo}"/>
							</a4j:commandLink>
						</rich:column>
						</rich:columnGroup>
					</rich:dataTable>
					 <div class="field-clear"></div>
					<div class="grid-12-12">
						<rich:datascroller align="center" renderIfSinglePage="false" for="membroPesquisaTable" />
					</div>
				</div>
				<div class="grid-5-12" >
				 <h:panelGroup  id="pgResultados">
					<h:panelGroup rendered="#{membroRelatorioBean.registroNaoEncontrado}" >
								<h:outputText styleClass="infoRegistroNaoEnc" value="#{msg['info.MGS_01']}"  />
					</h:panelGroup>
				</h:panelGroup>	
				</div>
				<h:panelGroup id="pgExibirMembroSelecionados">
				<div class="field-clear"></div>	 
				<div style="padding: 10px" >
					 	<rich:dataTable  
		                    width="750" border="0" id="membrosSelecionados" 
		                    styleClass="dataTable rich-table rich-table-cell ui-widget-content ui-grid-content"
		                    rendered="#{not empty membroRelatorioBean.listaMembrosSelecionados}" rows="10"
		                      var="membroSelecionado" value="#{membroRelatorioBean.listaMembrosSelecionados}" >
						  <f:facet  name="header">
		                    <rich:columnGroup >
		                            <rich:column style="text-align: center;width:200px"  styleClass="ui-state-default" >
		                                <strong><h:outputText value="NOME" /></strong>
		                            </rich:column>
		                             <rich:column style="text-align: center;width:30px"  styleClass="ui-state-default" >
		                                <strong><h:outputText value="Ação" /></strong>
		                            </rich:column>
		                    	</rich:columnGroup>
		                  </f:facet>
		 				<rich:columnGroup >	
							 <rich:column style="text-align:left">
								<h:outputText value="#{membroSelecionado.nome}" />
							</rich:column>
							<rich:column style="text-align:center">
								<a4j:commandLink id="remover" ajaxSingle="true" 
										action="#{membroRelatorioBean.excluirDaListaSelecionados}"
										 reRender="pgExibirMembroSelecionados,pgExibirBtImprimir"  >
									 <h:graphicImage value="/resources/imagens/btn_excluir.png" id="gIExcluirMembroVos" styleClass="hidelink"/>
								   <f:setPropertyActionListener target="#{membroRelatorioBean.membroVoSelecionado}" value="#{membroSelecionado}"/>
								</a4j:commandLink>
							</rich:column>
						</rich:columnGroup>
					
					</rich:dataTable>
					<div class="grid-11-12">
					<rich:datascroller align="center" renderIfSinglePage="false" for="membrosSelecionados" />
					</div>
				</div>	
				</h:panelGroup>
			
				 <div class="field-clear"></div>
				 
				  <a4j:region>
				  <h:panelGroup id="pgExibirBtImprimir">
					  <h:panelGroup rendered="#{membroRelatorioBean.exibirImprimir}" >
					   <div class="grid-2-12">
						<div style="padding-bottom: 20px;" >
							<a4j:commandLink id="cmdImprimir"  onclick="Richfaces.showModalPanel('panelImprimir');" immediate="true" styleClass="form-button"  value="Imprimir" >
							 		 <f:setPropertyActionListener target="#{membroRelatorioBean.listaResult}" value="#{membroRelatorioBean.listaMembrosVos}"/>
							</a4j:commandLink>
						</div>
						</div>
						</h:panelGroup>
					</h:panelGroup>
				 </a4j:region>
				
			</h:panelGroup>
		</h:panelGroup>	
		 
	
	
	</h:form>	
	</div>
	<ui:include src="/views/cadastro/modalImprimir.xhtml" />
		
			<t:saveState value="#{membroRelatorioBean.exibirImprimir}"/>
			<t:saveState value="#{membroRelatorioBean.membroVoSelecionado}"/>
			<t:saveState value="#{membroRelatorioBean.listaMembrosSelecionados}"/>
			<t:saveState value="#{membroRelatorioBean.listaOperacoes}"/>
			<t:saveState value="#{membroRelatorioBean.listaOpcoes}"/>
			<t:saveState value="#{membroRelatorioBean.listaMembrosVos}"/>
			<t:saveState value="#{membroRelatorioBean.parametroPesquisa}"/>
			<t:saveState value="#{membroRelatorioBean.listaParametros}"/> 
			<t:saveState id="membroVo" value="#{membroCadastro.coMembro}"/>
			<t:saveState value="#{membroCadastro.membroPesquisa}"/>
			<t:saveState value="#{membroRelatorioBean.tipoMembro}"/>
			<t:saveState value="#{membroRelatorioBean.tipoPesquisa}"/>
	</ui:define>
</ui:composition>
